"""
时间复杂度：O(log2n)
"""
def binary_search(l, value, start=None, end=None):
    start = start if start else 0
    end = end if end else len(l) - 1
    if start <= end:
        mid = start + (end-start) // 2
        if l[mid] == value:
            return mid
        elif l[mid] < value:
            return binary_search(l, value, mid + 1, end)
        else:
            return binary_search(l, value, start, mid - 1)
    else:
        return None


if __name__ == '__main__':
    l = [1,2,5,6,7,8,12,45,56]
    index = binary_search(l, 5)
    print(index)

    def dec(f):
        n=3
        def wrapper(*args, **kwargs):
            return f(*args, **kwargs) * n
        return wrapper

    @dec
    def foo(n):
        return n*2
    print(foo(2))

    li = [1, 4, 4, 6, 2, 6, 5, 8, 7]
    new_list = list(set(li))
    new_list.sort(key=li.index)
    print(new_list)

    nums = sum((i for i in range(0, 51)))
    print(nums)
    dict1 = {'a': '1', 'b': '2'}
    dict2 = {'b': 1}
    new_dict = dict(dict1, **dict2)
    dict1.update(dict2)
    print(new_dict)
    print(dict1)
